var onLoadHooks = new Array();
var required_for_action = new Array();
var inactivity_time = 0;

function
toggle(obj)
    {
    if ( typeof obj.checked == 'boolean' )
        {
        obj.checked ? obj.checked = false : obj.checked = true;
        }
    }

function
save_notes()
    {
    var xmlhttp = getXMLHTTP();
    if (xmlhttp)
        {
        var notes = document.getElementById("notes");
        var action_id = notes.action_id;
        var notes = document.getElementById("notes_text").value;

        xmlhttp.open( "GET", cgi_href + "/ep_get_notes.pl?action_id=" + action_id + "&notes=" + notes + '&now=' + new Date(), true );
        xmlhttp.onreadystatechange = function ()
            {
            if ( xmlhttp.readyState == 4 && xmlhttp.responseText )
                {
                if ( xmlhttp.responseText == "SAVED" )
                    {
                    hide_notes ();
                    }
                else
                    {
                    alert( "Failed to save note: " + xmlhttp.responseText );
                    }
                }
            }
        xmlhttp.send(null);
        }
    }

function
hide_notes()
    {
    document.getElementById("notes").style.display="none";
    }

function
show_notes(action_id)
    {
    var xmlhttp = getXMLHTTP();
    if (xmlhttp)
        {
        var notes = document.getElementById("notes");

        notes.style.display = "";
        notes.action_id = action_id;
    
        document.getElementById("notes_text").value = "Loading notes...";

        xmlhttp.open( "GET", cgi_href + "/ep_get_notes.pl?action_id=" + action_id + '&now=' + new Date(), true );
        xmlhttp.onreadystatechange = function ()
            {
            if ( xmlhttp.readyState==4 && xmlhttp.responseText )
                {
                document.getElementById("notes_text").value = xmlhttp.responseText;
                }
            }
        xmlhttp.send(null);
        }
    }

// kolais: what is it?
function
toggle_size_epc(img)
    {
    var epc = document.getElementById("epc_table");
    if ( epc.getAttribute("width") == 750 )
        {
        epc.setAttribute( "width", "95%" );
        document.mainfrm.epc_size_state.value = 1;
        img.src = html_href + "/static/images/ep_window_bar_button_Dot.png";
        img.setAttribute( "title", "Restore" );
        }
    else
        {
        epc.setAttribute( "width", "750" );
        document.mainfrm.epc_size_state.value = 0;
        img.src = html_href + "/static/images/ep_window_bar_button_plus.png";
        img.setAttribute ( "title", "Maximize" );
        }
    }

// kolais: data management code -- should go to relevant module
function
DM_change_current_folder(new_current_folder_id)
    {
    var old_current_folder = document.getElementById( "folder_" + document.mainfrm.current_folder_id.value );
    var new_current_folder = document.getElementById( "folder_" + new_current_folder_id );

    if (old_current_folder)
        old_current_folder.style.fontWeight = '';

    if (new_current_folder)
        new_current_folder.style.fontWeight = 'bold';

    document.mainfrm.current_folder_id.value = new_current_folder_id;
    document.mainfrm.current_root_dataset_id.value = "";
    }

// kolais: subsection supporting code -- should go to relevant module

function show_subsection( comp, sec, subsec )
    {
    // when changing display, always test for EPC_not_processed_OK,
    // because it might contain the id of a component that wasn't
    // processed, and thus should be active, overriding anything else.
    if ( document.mainfrm.EPC_not_processed_OK )
        {
        document.mainfrm.render_component_ids.value = document.mainfrm.EPC_not_processed_OK.value;
        }
    else
        {
        document.mainfrm.active_component_id.value = "";
        }

    var s = eval( "document.mainfrm.active_subsection_id___c_" + String(comp) + "_s_" + sec );

    oldsec = document.getElementById( "subsection_" + sec + "_" + s.value );
    newsec = document.getElementById( "subsection_" + sec + "_" + subsec );

    oldsectd = document.getElementById( "td_subsection_" + sec + "_" + s.value );
    newsectd = document.getElementById( "td_subsection_" + sec + "_" + subsec );

    oldsectds = document.getElementById( "tds_subsection_" + sec + "_" + s.value );
    newsectds = document.getElementById( "tds_subsection_" + sec + "_" + subsec );

    oldsecshs = document.getElementById( "shs_subsection_" + sec + "_" + s.value );
    newsecshs = document.getElementById( "shs_subsection_" + sec + "_" + subsec );

    oldsec.style.display = "none";
    newsec.style.display = "";

    oldsecshs.style.display = "none";
    newsecshs.style.display = "";

    oldsectd.className = "tablebody";
    newsectd.className = "tablegreen";

    oldsectds.className = "green";
    newsectds.className = "smallwhite";

    oldsectd.style.border = "1px solid #000000";
    newsectd.style.border = "";

    s.value = subsec;
    }

function
saveas_action(actid)
    {
    if ( !actid )
        {
        alert("Cannot export this item!");
        return;
        }

    if ( confirm("Export selected item as a new data set?") )
        {
        document.mainfrm.action.value = "saveas_action";
        document.mainfrm.active_component_id.value = document.mainfrm.component.value;
        eval( "document.mainfrm.chk_meta_" + actid + ".checked = true" );
        submit_component( document.mainfrm.component.value, document.mainfrm.component.value + ':' + document.mainfrm.component.value + ':-1' );
        }
    }

function
change_current_action(actid)
    {
    document.mainfrm.current_action_id.value = actid;
    update_action_metadata(actid);
    }

function
change_current_cluster_selection( actid, direction, left, right )
    {
    document.mainfrm.current_action_id.value = actid;
    update_action_metadata(actid);

    if ( direction == 0 )
        {
        direction = "row";
        }
    else
        {
        direction = "col";
        }

    document.mainfrm.current_cluster_selection.value = actid + "_" + direction + "_cluster_" + left + ":" + right;
    }

function
change_current_metadata_selection( actid, mid )
    {
    document.mainfrm.current_action_id.value = actid;
    update_action_metadata(actid);

    document.mainfrm.current_metadata_selection.value = mid;
    }

function
update_action_metadata(actid)
    {
    if ( !arrActions[actid] )
        return;

    for ( action_property in arrActions[actid] )
        {
        var action_property_elt = document.getElementById(action_property);
        if (action_property_elt)
            {
            if (action_property_elt.src)
                {
                var lp_vals = arrActions[actid][action_property].split(";");
                if ( /svg$/.test(lp_vals[0]) )
                    {
                    lp = document.createElement("embed");
                    lp.type = "image/svg+xml";
                    lp.width = lp_vals[1] || action_property_elt.width;
                    lp.height = lp_vals[2] || action_property_elt.height;
                    }
                else
                    {
                    lp = document.createElement("img");
                    }

                lp.src = lp_vals[0];
                lp.id = action_property;

                pNode = action_property_elt.parentNode;
                pNode.replaceChild( lp, action_property_elt );
                }
            else if ( action_property_elt.tagName == "SELECT" )
                {
                action_property_elt.options.length = 0;
                var svals = arrActions[actid][action_property].split(";");
                for ( v in svals )
                    {
                    var o = new Option( svals[v], v );
                    action_property_elt.options[action_property_elt.options.length] = o;
                    }
                }
            else
                {
                action_property_elt.value = arrActions[actid][action_property];
                }
            }
        }
    }

function
select_items( sel_textarea, select )
    {
    var current_action_id = document.mainfrm.current_action_id.value;
    var w = window.open
                ( arrActions[document.mainfrm.current_action_id.value]["select" + select]
                , "select" + select
                , "height=500, width=250, left=300, top=100, status=yes, toolbar=no, scrollbars=yes, menubar=no, location=no, resizable=yes"
                );
    window.items = document.getElementById(sel_textarea);
    w.focus();
    }

function
define_new_factors(choose_factors_select)
    {
    var current_action_id = document.mainfrm.current_action_id.value;
    var w = window.open
                ( cgi_href + "/ep_manage_factors.pl?action_id=" + current_action_id
                , "manage_factors"
                , "height=300, width=500, left=300, top=100, status=yes, toolbar=no, scrollbars=yes, menubar=no, location=no, resizable=yes"
                );
    w.focus();
    }

function
select_action( actid, chk_ac, sel_act_input )
    {
    if ( chk_ac.checked && selected_actions >= arrSelectedActions.length )
        {
        alert( "You need to select exactly " + selectable_actions + " actions." );
        chk_ac.checked = false;
        return;
        }

    if ( !chk_ac.checked )
        {
        remove_selected_action(actid);
        }
    else
        {
        add_selected_action(actid);
        }

    update_selected_actions_input(sel_act_input);
    }

function
update_selected_actions_input(sel_act_input)
    {
    var s = "";
    for ( i in arrSelectedActions )
        {
        if (arrSelectedActions[i])
            s += arrSelectedActions[i] + ",";
        }

    s = s.replace( /,$/, "" ); // remove last (extraneous) separating comma
    sel_act_input.value = s;
    }

function
remove_selected_action(actid)
    {
    for ( i in arrSelectedActions )
        {
        if ( arrSelectedActions[i] == actid )
            {
            arrSelectedActions[i] = "";
            selected_actions--;
            return;
            }
        }
    }

function add_selected_action ( actid ) {
  for ( var i = 0; i < arrSelectedActions.length; i++ ) {
    if ( !arrSelectedActions[i] ) {
      arrSelectedActions[i] = actid;
      selected_actions++;
      return;
    }
  }
}

function hide_component ( comp ) {
  if ( document.mainfrm.EPC_not_processed_OK ) {
    document.mainfrm.render_component_ids.value = document.mainfrm.EPC_not_processed_OK.value;
  } else {
    document.mainfrm.active_component_id.value = "";
  }

  var s = eval ( "document.mainfrm.display_component_" + String(comp) );
  s.value = 0;
  document.mainfrm.submit();
}

function show_component ( comp ) {
  if ( document.mainfrm.EPC_not_processed_OK ) {
    document.mainfrm.render_component_ids.value = document.mainfrm.EPC_not_processed_OK.value;
  } else {
    document.mainfrm.active_component_id.value = "";
  }

  var s = eval ( "document.mainfrm.display_component_" + String(comp) );
  s.value = 1;
  document.mainfrm.submit();
}

// kolais: working on this ...
function
submit_component( id, target_id )
    {
    document.mainfrm.active_component_id.value = id;
    var s = eval( "document.mainfrm.targets___c_" + String(id) );
    s.value = target_id;

    display_status_window();
    //alert( "submitting " + document.mainfrm.active_component_id.value );
    document.mainfrm.submit();
    }

function
cancel_component( this_epc_id, prev_epc_id )
    {
    document.mainfrm.action.value = "cancel_last_action";
    submit_component( this_epc_id, prev_epc_id + ':' + prev_epc_id + ":cancel_last_action" );
    }


function
resize_container_frame ( doc ) {
  var container_frame = document.getElementById ('container_frame');

  container_frame.height = doc.body.scrollHeight + 30;
  container_frame.width  = doc.body.scrollWidth  + 30;
}

var cancel_status_win = 0;

function
display_status_window(is_not_first_call)
    {
    var es = document.getElementById("ep_status_window");
    es.style.display = "block";

    var xmlhttp = getXMLHTTP();
    if (xmlhttp)
        {
        var ep_status = document.getElementById("ep_status_text");
    
        document.getElementById("ep_status_text").value = "Checking progress...";
        var sid = getCookie("ep_session_id");

        xmlhttp.open( "GET", cgi_href + "/ep_status.pl?session_id=" + escape(sid) + ( is_not_first_call ? '' : '&firsttime=1' ) + '&now=' + new Date(), true );
        xmlhttp.onreadystatechange = function ()
            {
            if ( xmlhttp.readyState == 4 )
                {
                if ( !xmlhttp.responseText.match( /DONE/ ) )
                    {
                    if ( !cancel_status_win )
                        setTimeout( "display_status_window(1)", 1500 );

                    document.getElementById("ep_status_text").innerHTML = xmlhttp.responseText;
                    }
                else
                    {
                    document.getElementById("ep_status_text").innerHTML = "Please wait...";
                    }

                }
            }

        xmlhttp.send(null);
        }
    }

function new_folder ( folder_id ) {
  var user = $("#ep_user_name").text();
  if (!user || user == "" || String(user).toLowerCase() == "guest") {
    alert("Guests are not allowed to create subfolders.");
    return;
  }

  var answer = prompt("Please specify new folder name", "");

  if ( answer.value != '' ) {
    document.mainfrm.folder.value = answer;
    document.mainfrm.action.value = 'new_folder';
    document.mainfrm.active_component_id.value = document.mainfrm.component.value;
    document.mainfrm.new_folder_parent.value = folder_id;
    submit_component ( document.mainfrm.component.value, document.mainfrm.component.value + ':' + document.mainfrm.component.value + ':-1' );
  }
}

function delete_folder ( folder_id ) {
  var user = $("#ep_user_name").text();
  if (!user || user == "" || String(user).toLowerCase() == "guest") {
    alert("Guests are not allowed to delete folders.");
    return;
  }
  if ( confirm ( "Are you sure you want to delete this folder and everything below?" ) ) {
    document.mainfrm.action.value = 'delete_folder';
    document.mainfrm.active_component_id.value = document.mainfrm.component.value;
    eval ( "document.mainfrm.chk_folder_" + folder_id + ".checked = true" );
    submit_component ( document.mainfrm.component.value, document.mainfrm.component.value + ':' + document.mainfrm.component.value + ':-1' );
  }
}

function delete_dataset ( dataset_id ) {
  if ( confirm ( "Are you sure you want to delete this dataset and its entire analysis history?" ) ) {
    document.mainfrm.action.value = 'delete_dataset';
    document.mainfrm.active_component_id.value = document.mainfrm.component.value;
    eval ( "document.mainfrm.chk_dataset_" + dataset_id + ".checked = true" );
    submit_component ( document.mainfrm.component.value, document.mainfrm.component.value + ':' + document.mainfrm.component.value + ':-1' );
  }
}

function delete_action ( action_id ) {
  if ( confirm ( "Are you sure you want to delete this action and everything below?" ) ) {
    document.mainfrm.action.value = 'delete_action';
    document.mainfrm.active_component_id.value = document.mainfrm.component.value;
    eval ( "document.mainfrm.chk_action_" + action_id + ".checked = true" );
    submit_component ( document.mainfrm.component.value, document.mainfrm.component.value + ':' + document.mainfrm.component.value + ':-1' );
  }
}

function display_action ( action_id, epc_id ) {
  document.mainfrm.action.value = 'display_action' + ':' + action_id;
  document.mainfrm.active_component_id.value = epc_id;
  //  eval ( "document.mainfrm.chk_action_" + action_id + ".checked = true" );
  submit_component ( document.mainfrm.component.value, document.mainfrm.component.value + ':' + document.mainfrm.component.value + ':-1' );
}

function delete_selection () {
  if ( confirm ( "Are you sure you want to delete all the selected items (and their children)?" ) ) {
    document.mainfrm.action.value = 'delete_selection';
    document.mainfrm.active_component_id.value = document.mainfrm.component.value;
    submit_component ( document.mainfrm.component.value, document.mainfrm.component.value + ':' + document.mainfrm.component.value + ':-1' );
  }
}

function select_all () {
  var inputs = document.getElementsByTagName ( "input" );

  for ( var input = 0; input < inputs.length; input++ ) {
    if ( inputs[input].getAttribute("type") == "checkbox" ) {
      if ( /chk_folder|chk_dataset|chk_action/.test ( inputs[input].getAttribute("name") ) ) {
	inputs[input].checked = true;
      }
    }
  }
}

function cancel_status_window () {
  clear_status_window ();

  if ( window.stop ) 
    window.stop();
  else
    document.execCommand('Stop');

  cancel_status_win = 1;
}

function clear_status_window () {
  window.status='';

  //  var ep_status = document.getElementById ( "ep_status" );
  //  if ( ep_status.src ) ep_status.src="";
 
  var es = document.getElementById ( "floatlayer" );
  es.style.display = "none";
}

function onPageLoad () {
  var sid = getCookie ("ep_session_id");

  if ( sid ) {
    var slog_loc = slog.location.href;

    if ( slog_loc.indexOf('?') != -1 ) 
      slog_loc = slog_loc.substr(0, slog_loc.indexOf('?'));
    
    slog_loc += "?ep_session_id=" + escape( sid) ;
    slog.location = slog_loc;
  }

  if ( username ) {
    setEltHTML ( "logged_in_username", username );
  }

  show_inactive_time ();
  clear_status_window ();
  
  //  resize_epc_table ();

  for ( i = 0; i < onLoadHooks.length; i++ ) {
    var F = onLoadHooks[i];
    F();
  }
}

function resize_epc_table () {
  var epc = document.getElementById ( "epc_table" );
  epc.width = document.body.clientWidth - 50;
}

function show_inactive_time () {
  var formatted_time;

  if ( inactivity_time < 60*1000 ) {
    formatted_time = inactivity_time / 1000 + " seconds";
  } else {
    formatted_time = Math.round (inactivity_time / (60*1000) ) + " minutes";
  }

  formatted_time =  session_duration - Math.round (inactivity_time / (60*1000) );

  if ( formatted_time < 0 ) {
    formatted_time = "<b style='color:red'>session expired!</b>";
    setEltHTML ( "session_timeout", formatted_time );
  } else {
    formatted_time += " min";
    setEltHTML ( "inactivity_time", formatted_time );

    inactivity_time += 1000 * 60;
    window.setTimeout("show_inactive_time()", 1000 * 60 );
  }
}

function setEltHTML ( elt_id, html ) {
  var elt = document.getElementById ( elt_id );
  if ( elt )
    elt.innerHTML = html;
}

function getCtxtHelp ( ctxt_id ) {
  var elt = document.getElementById ( ctxt_id );
  if (elt)
    return elt.innerHTML;
}

function epc_help ( url ) {
  if ( url ) {
    var win = open_window ( html_href + url, 'epc_help' );
  } else {
    if ( !document.mainfrm.render_component_ids ) return;
    var win = open_window ( cgi_href + '/epc_help.pl?epc_id=' + document.mainfrm.render_component_ids.value, 'epc_help' );
  }

  win.focus();
}

function open_window ( url, title ) {
  return window.open( url, title, 'location=no,resizable=no,menubar=no,scrollbars=yes,status=yes,titlebar=no,toolbar=no,fullscreen=no,width=560,height=400,left=200,top=200' );
}

function setCtxtHelp ( ctxt_id ) {
  if ( !show_context_help ) return;
  var ctxt = document.getElementById ( ctxt_id );
  if ( ctxt ) {
    var x = ctxt.innerHTML;
    stm(["",x],["","","","","",,"black","#ffffe1","","","",,,,1,"black",2,24,0.3,,2,"gray",1,,-2,19]);
    //    var helpDiv = document.getElementById ( "context_help" );
    //    if ( helpDiv )
    //      helpDiv.innerHTML = document.getElementById ( ctxt_id ).innerHTML;
    //  }
  }
}

function seeobj ( obj ) {
  s = "";
  for ( e in obj ) {
    try {
      s += e + " : " + obj[e] + "\n";
    }
      catch (e) {};
  }

  alert (s);
}

function seeobjw ( obj ) {
  s = "";
  for ( e in obj ) {
    try {
      s += e + " : " + obj[e] + "\n";
    }
      catch (e) {};
  }

  w = window.open ();
  w.document.write( s );
}

// will log the user off and reload the interface 
// takes the prompt as an argument, if prompt is empty, will use the default prompt
function log_off ( noprompt ) {
  var do_logoff = false;
  
  if ( !username )
    return; // not logged on!

  if ( noprompt ) {
    do_logoff = confirm ( noprompt );
  } else {
    do_logoff = confirm ( "You are currently logged on as " + username + ". Are you sure you want to log off?" );
  }

  if ( do_logoff ) {
    try {
      top.document.mainfrm.active_component_id.value  = "";
      top.document.mainfrm.render_component_ids.value = 0;
      top.document.mainfrm.kill_session.value         = getCookie ("ep_session_id");
      
      top.document.mainfrm.submit();
    } catch (exc) {
      alert ( "Return to an EP component display to log off." );
    }
  }
}

// Heinle's function for retrieving a cookie.
function getCookie(name){
  var cname = name + "=";
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

// An adaptation of Dorcht's function for setting a cookie.
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

// An adaptation of Dorcht's function for deleting a cookie.
function delCookie (name,path,domain) {
  document.cookie = "";
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function toggle_visibility ( obj_id, icon, message ) {
  var obj_elt        = document.getElementById ( obj_id );
  var obj_elt_toggle = document.getElementById ( obj_id + "_toggle" );
  var obj_elt_visible = document.getElementById ( obj_id + "_visible" );

  if ( obj_elt.style.display == 'none' ) {
    obj_elt.style.display  = '';
    if ( obj_elt_toggle ) {
      obj_elt_toggle.title = "Hide " + message;
      obj_elt_toggle.src = html_href + "/static/images/gui_icons/" + icon + "_dn.png";
    }
  } else {
    obj_elt.style.display  = 'none';
    if ( obj_elt_toggle ) {
      obj_elt_toggle.title = "Show " + message;
      obj_elt_toggle.src = html_href + "/static/images/gui_icons/" + icon + "_up.png";
    }
  }
}

///////////////////////////////////////////////////////////////////////////////////////////
function clickOnEntity ( entity_id ) {
  //  if (!e) var e = window.event;
  //  e.cancelBubble = true;
  //  if (e.stopPropagation) e.stopPropagation();

  var entity = document.getElementById ( "entity_" + entity_id );

  if ( entity.getAttribute("open") == "false" ) {
    expand ( entity, entity_id );
  }  else {
    collapse ( entity, entity_id );
  }
}

function expand ( entity, entity_id ) {
  var stateImage;
  var oImage;

  stateImage = document.getElementById ( "stateImage" + entity_id );
  
  //  oImage = entity.childNodes(0).all["image"]
  //  oImage.src = entity.imageOpen

  if ( stateImage ) {
    stateImage.src = stateImage.getAttribute("_open"); //stateImage._open;
  }

  for ( i = 0; i < entity.childNodes.length; i++ ) {
    if ( entity.childNodes[i].tagName == "DIV" ) {
      entity.childNodes[i].style.display = "block";
    }
  }
  
  entity.setAttribute ("open", "true");
}

function collapse ( entity, entity_id ) {
  var stateImage;
  var oImage;
  var i;

  stateImage = document.getElementById ( "stateImage" + entity_id );

  //  oImage = entity.childNodes(0).all["image"]
  //  oImage.src = entity.image

  if ( stateImage ) {
    stateImage.src = stateImage.getAttribute("_closed"); //stateImage._closed;
  }

  for ( i = 0; i < entity.childNodes.length; i++ ) {
    if ( entity.childNodes[i].tagName == "DIV" ) {
      entity.childNodes[i].style.display = "none";
      //        collapse ( entity.childNodes[i] );
    }
  }
    
  entity.setAttribute ("open", "false");
}

function expandAll(entity) {
  var oImage
  var i

  expand(entity, false)

  for(i=0; i < entity.childNodes.length; i++) {
    if(entity.childNodes(i).tagName == "DIV") {
      expandAll(entity.childNodes(i))
    }
  }
}

// select a new arrayexpress bioassay data group by id, dehighlight currently selected one.
function select_arrayexpress_badg ( id, name ) {
  var cur_badg_id = document.getElementById ( "arrayexpress_badg_input" ).value;

  if ( cur_badg_id ) {
    var cur_badg_elt = document.getElementById ( "badg_" + cur_badg_id );
    if ( cur_badg_elt ) cur_badg_elt.style.fontWeight = "normal";
  }

  document.getElementById ( "badg_" + id ).style.fontWeight = "bold";
  document.getElementById ( "arrayexpress_badg_input" ).value = id;
  document.getElementById ( "dataset_name" ).value = name;

  if ( this_accnum ) {
    document.getElementById ( this_accnum ).style.color = "red";
  }
}

function png_select_subtree ( leftmost, rightmost, lh, rh, tree_id ) {
  var name = prompt ( "You can name the cluster to be saved:" );
  if (!name || name == null)
    return;
  var xmlhttp = getXMLHTTP();

  if ( xmlhttp ) {
    clusters = lh + "," + rh + "," + name + "," + leftmost + "," + rightmost;

    xmlhttp.open ( "GET", cgi_href + "/ep_save_clusters.pl?clusters=" + clusters + '&tree_id=' + tree_id, true );

    xmlhttp.onreadystatechange = function () {
      if ( xmlhttp.readyState == 4 && xmlhttp.responseText ) {
	alert ( xmlhttp.responseText );
      }
    };
    xmlhttp.send(null);
  }
}

var this_accnum = "";
function toggle_experiment(accnum) {
  if ( this_accnum != accnum ) { 
    this_exptelt = document.getElementById ( 'desc-' + this_accnum ); 
    if ( this_exptelt ) this_exptelt.style.display = "none";
    this_accnumelt = document.getElementById ( this_accnum );
    if ( this_accnumelt ) this_accnumelt.style.color = "black";
  }

  var exptelt = document.getElementById ( 'desc-' + accnum );

  if ( exptelt.style.display == "none" )
    exptelt.style.display = "";
  else
    exptelt.style.display = "none";

  this_accnum = accnum;
}
